class IssuesMilestones
  attr_accessor :github

  def initialize(github)
    @github = github
  end

  def listRepoMilestones(repo, state=nil, sort=nil, direction=nil, user=nil)
    params = {
        :state => state,
        :sort => sort,
        :direction => direction,
    }
    params = @github.removeEmptyParams(params)
    url = 'repos/%s/%s/milestones?%s' % [user, repo, @github.parameterize(params)]
    @github.get(url)
  end

  def getMilestone(repo, number, user=nil)
    url = 'repos/%s/%s/milestones/%s' % [repo, user, number]
    @github.get(url)
  end

  def createMilestone(repo, title, state=nil, description=nil, due_on=nil, user=nil)
    params = {
        :title => title,
        :state => state,
        :description => description,
        :due_on => due_on
    }
    params = @github.removeEmptyParams(params)
    data = params.to_json
    url = 'repos/%s/%s/milestones' % [repo, user]
    @github.post(url, data)
  end

  def updateMilestone(repo, number, title, state=nil, description=nil, due_on=nil, user=nil)
    params = {
        :title => title,
        :state => state,
        :description => description,
        :due_on => due_on
    }
    params = @github.removeEmptyParams(params)
    data = params.to_json
    url = 'repos/%s/%s/milestones/%s' % [repo, user, number]
    @github.patch(url, data)
  end

  def deleteMilestone(repo, number, user=nil)
    url = 'repos/%s/%s/milestones/%s' % [repo, user, number]
    @github.delete(url)
  end
end